<?php
use yii\helpers\Url;
use yii\captcha\Captcha;

?>
<div class="tpl-login">
    <div class="tpl-login-content">



        <form class="am-form tpl-form-line-form">
            <div class="am-form-group">
                <input type="text" class="tpl-form-input" id="username" placeholder="请输入账号">

            </div>

            <div class="am-form-group">
                <input type="password" class="tpl-form-input" id="password" placeholder="请输入密码">

            </div>
            <div id="captcha" style="<?php if(!$wrong){?>display: none<?php }?>" class="am-form-group" >
                <input style="width: 70%;display: inline-block;" type="text" class="tpl-form-input" id="code" placeholder="请输入验证码">
                <?=Captcha::widget(['name'=>'captchaimg','captchaAction'=>'captcha','imageOptions'=>['id'=>'captchaimg', 'title'=>'换一个', 'alt'=>'换一个', 'style'=>'cursor:pointer'],'template'=>'{image}']);?>
            </div>
            <div class="am-form-group tpl-login-remember-me">
                <a class="am-link-muted">忘记密码？</a>
                <a class="am-link-muted" data-am-popover="{theme: 'warning lg',content: '<img src=\'/assets/img/Qrcode.jpg\'>', trigger: 'hover focus'}"><i class="am-icon-mobile am-icon-fw"></i>APP</a>
            </div>






            <div class="am-form-group">

                <button type="button" id="login" class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success  tpl-login-btn">登陆</button>

            </div>
        </form>
    </div>
</div>


<script type="text/javascript">
    document.onkeydown = function(e){
        var ev = document.all ? window.event : e;
        if(ev.keyCode==13) {

            $("#login").click();

        }
    }
    $("#login").click(function(){
        $("input").blur();
        var csrf=$('meta[name="csrf-token"]').attr("content");
        var username= $("#username").val();
        var password=$("#password").val();
        var captcha=$("#code").val();
        if(username==''){
            $.alert("警告","用户名不能为空！","确定");
            return ;
        }
        if(password==''){
            $.alert("警告","密码不能为空！","确定");
            return ;
        }


        $.ajax({
            url:"<?=Url::to(['site/sign-up'])?>",
            data:'_csrf='+csrf+"&username="+username+"&password="+password+"&captcha="+captcha,
            type:'post',
            dataType:'json',
            success:function(data){
                if(data.status){
                    alert("登陆成功！以后跳转首页");
                }else{
                    $.alert("警告",data.msg,"确定");
                    $("#captcha").show();
                }
            },
            error:function(){
                $.alert("警告","<?=Yii::t('app','Some error in servers')?>","确定");
               
            }
        })
    })
</script>